<script setup lang="ts">
  import { HMessage, HMessageBox } from '@/components/common/message'
  import { useCheckReceivePayment } from '@/services/pages/withdrawal/receive-payment/useReceivePayment'
  import { PropType, watch } from 'vue'

  const { checkForm, checkLoading, check, resetForm } = useCheckReceivePayment()

  const props = defineProps({
    idList: {
      type: Array as PropType<Array<string>>,
      required: true,
    },
  })

  const emits = defineEmits<{
    (e: 'update'): void
  }>()

  // 弹窗显示状态
  const visible = defineModel('modelValue', { type: Boolean, default: false })

  /**
   * 隐藏弹窗
   */
  const hideDialog = () => {
    visible.value = false
    resetForm()
  }

  /**
   * 确定事件
   */
  const onConfirm = async () => {
    const res = await check()
    if (res.code === 20000) {
      emits('update')
      hideDialog()
      HMessage.success('审核成功')
      return
    }
    HMessageBox.error(res.message)
  }

  watch(visible, (value) => {
    if (value && props.idList.length > 0) {
      checkForm.value.receivePaymentIds = props.idList
    }
  })
</script>

<template>
  <h-dialog v-model="visible" :loading="checkLoading" title="审核收款单" @close="hideDialog">
    <el-form :model="checkForm" inline-message class="modal_form_content" label-position="top">
      <el-form-item label="审核备注">
        <el-input
          v-model="checkForm.remark"
          type="textarea"
          maxlength="100"
          resize="both"
          placeholder="请输入审核备注"
          show-word-limit
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <h-button type="primary" is-modal @click="onConfirm">审核通过</h-button>
      <h-button is-modal @click="hideDialog">取消</h-button>
    </template>
  </h-dialog>
</template>

<style scoped lang="scss">
  :deep(.el-textarea__inner) {
    width: 100% !important;
    height: 120px !important;
  }
</style>
